use serde::Deserialize;
use serde::Serialize;
use ts_rs::TS;
use yata::core::PeriodType;
use yata::core::ValueType;

use super::IndicatorActionWrap;

///
/// Struct to hold the results of Struct yata::indicators::WoodiesCCI
///
///
#[derive(Serialize, Deserialize, Default, Debug, TS, Clone)]
#[ts(export)]
pub struct WCCI {
    /// 1 signals
    /// When Trend CCI stays above zero line for s1_lag bars, returns full buy signal.
    /// When Trend CCI stays below zero line for s1_lag bars, returns full sell signal.
    /// Otherwise returns no signal.
    pub signal0: Option<IndicatorActionWrap>,

    ///2 values
    /// Turbo CCI value
    /// Range in (-inf; +inf)
    pub turbo: ValueType,

    ///Trend CCI value
    /// Range in (-inf; +inf)
    pub trend: ValueType,
}

/// Configuration
#[derive(Serialize, Deserialize, Debug, TS, Clone, Copy)]
#[ts(export)]
pub struct WCCIConfig {
    /// Turbo CCI: with period 6
    /// Turbo CCI period
    pub period1: PeriodType,

    /// Trend CCI: Is used to determine the trend as well as to determine entry signals.
    /// Ken Wood recommends setting CCI with period of 14 for time frames, shorter than 60 minutes
    /// and a period of 20 for time frames higher than 60 minutes.
    /// 趋势CCI：用于判断趋势方向以及确定入场信号。Ken Wood建议，对于60分钟以下的时间框架，将CCI指标的周期设置为14；而对于60分钟以上的时间框架，则将CCI指标的周期设置为20。
    /// Trend CCI period
    pub period2: PeriodType,

    /// For the trend definition, we only use the CCI Trend. Therefore, we do not use higher time frame. Note that CCI Trend warns us of an approaching trend with a yellow line, which marks the trend change.
    /// Definition of up trend:
    /// Six lines above the Zero-Line
    /// Definition of short tend
    /// Six lines below the Zero-Line
    /// Signal #1 bars count to occur
    pub s1_lag: PeriodType,
    // source: Source
    // Source type of values. Default is Close
}

impl Default for WCCIConfig {
    fn default() -> Self {
        Self {
            period1: 6,
            period2: 20,
            s1_lag: 6,
        }
    }
}
